package com.itheima.tanhua.web;

import com.itheima.tanhua.service.RecommendService;
import com.itheima.tanhua.vo.mongo.pageResult;
import com.itheima.tanhua.vo.mongo.todayBestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 芝士雪豹
 * @create 2022/9/21/21:49
 */
@RestController
@RequestMapping("tanhua")
public class RecommendController {
    @Autowired
    private RecommendService recommendService;

    /**
     * 今日佳人
     *
     * @return
     */
    @GetMapping("todayBest")
    public ResponseEntity todayBest(@RequestHeader("Authorization") String token) {
        //业务层处理 填充所需要的属性
        todayBestVo todayBestVo = recommendService.todayBest(token);
        return ResponseEntity.ok(todayBestVo);
    }

    /**
     * 推荐朋友
     *
     * @return
     */
    @GetMapping("recommendation")
    public ResponseEntity recommendation(@RequestHeader("Authorization") String token,
                                         Integer page,
                                         Integer pageSize) {
        pageResult pageResult = recommendService.recommendation(token, page, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    //查询佳人信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        todayBestVo vo = recommendService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }
    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions( Long userId) {
        String questions = recommendService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }
    //查询陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity replayQuestions(@RequestBody Map map) {
        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        recommendService.replayQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }


}
